<div id="page_icons">
    <a onclick="return GB_showCenter('Nový záznam', this.href, 400, 600)" href="EditRow.php?table=<?=$_GET["table"]?>&amp;col=<?=$editkey?>" title="Přidat záznam"><img src="./templates/icons/add.png" /></a>
</div>

<table class="tables">
<form action="">
<input type="hidden" name="table" value="<?=$_GET["table"]?>" />
<tr>
<? foreach ($describe as $desc) { ?>
<?
if (!is_null($desc["forkey_string"]))
{
    $for_search = $GLOBALS["db"]->loadListPattern($desc["forkey"]["remote_table"], $desc["forkey"]["remote_field"], $desc["forkey_string"]);
?>
<? if ($desc["visible"]) { ?>    <td><select name="search[<?=$desc["field"]?>]"><option value=""></option><? foreach ($for_search as $s => $sv) {?> <option value="<?=$s?>"<?if ($_GET["search"][$desc["field"]] == $s) echo " selected";?>><?=$sv?></option> <?}?></select></td><? } ?>
<? } elseif ($desc["visible"] AND ($desc["content_type"] == "enum" OR $desc["content_type"] == "set")) { ?>
<td><select name="search[<?=$desc["field"]?>]"><option value=""></option><? foreach ($desc["options_set"] as $s => $sv) {?> <option value="<?=$s?>"<?if ($_GET["search"][$desc["field"]] == $s) echo " selected";?>><?=$sv?></option> <?}?></select></td>
<? } else {?>
<? if ($desc["visible"]) { ?>    <td><input type="text" name="search[<?=$desc["field"]?>]" style="width: 100%" value="<?=$_GET["search"][$desc["field"]]?>" /></td><? } ?>
<? } ?>
<? } ?>
<td><button type="submit">Hledej</button></td>
</tr>
</form>
<tr>
<? foreach ($describe as $desc) { if ($desc["editkey"]) $editkey = $desc["field"]; ?>
<? if ($desc["visible"]) { ?>    <th><? if(!empty($desc["set_title"])) echo $desc["set_title"]; else echo $desc["field"]; ?></th><? } ?>
<? } ?>
    <th style="width: 40px;"></th>
</tr>

<?
if (!isset($editkey))
{
    $editkey = "dbmister_where";
    foreach ($describe as $wdesc) $cols[] = $wdesc["field"];
    foreach ($data as &$wd)
    {
        foreach ($cols as $wcol) $wd["dbmister_where"][] = " `{$wcol}` = '{$wd[$wcol]}' ";
        $wd["dbmister_where"] = implode(" AND ", $wd["dbmister_where"]);
    }
    unset($wd);
}
?>

<? foreach ($data as $d) { $iter++; ?> 
<tr<? if ($iter % 2 == 0) echo " class=\"even\"" ?>>
<? foreach ($describe as $desc) if ($desc["visible"]) { ?>
<?
if (!is_null($desc["forkey_string"]))
{
    unset($string);
    $for_buff = $GLOBALS["db"]->loadValues($desc["forkey"]["remote_table"], $desc["forkey"]["remote_field"], $d[$desc["field"]]);
    
    foreach ($for_buff as $fbk => $fbv) $fb["[".$fbk."]"] = $fbv;
    unset($fbk); unset($fbv);
    
    $string = strtr($desc["forkey_string"], $fb);
    
    unset($for_buff);
?>
    <td><a onclick="return GB_showCenter('Editace řádku cizí tabulky', this.href, 400, 600)" href="EditRow.php?table=<?=$desc["forkey"]["remote_table"]?>&amp;col=<?=$desc["forkey"]["remote_field"]?>&amp;val=<?=$d[$desc["field"]]?>"><?if (!empty($string)) echo $string; else echo $d[$desc["value"]];?></a></td>
<? } else { ?>
    <td>
        <? if (($desc["content_type"] == "enum" OR $desc["content_type"] == "set") AND !empty($desc["options_set"])) { ?>
        <? if (!empty($desc["pattern"])) echo str_replace("#", $d[$desc["field"]], $desc["pattern"]); else echo $desc["options_set"][$d[$desc["field"]]]?>
        <? } else { ?>
        <? if (!empty($desc["pattern"])) echo str_replace("#", $d[$desc["field"]], $desc["pattern"]); else echo $d[$desc["field"]];?>
        <? } ?>
    </td>
<? } ?>
<? } ?>
<td><a onclick="return GB_showCenter('Editace řádku', this.href, 400, 600)" href="EditRow.php?table=<?=urlencode($_GET["table"])?>&amp;col=<?=urlencode($editkey)?>&amp;val=<?=urlencode($d[$editkey])?>"><img src="./templates/icons/pencil.png" /></a></td>
</tr>
<? } ?>
</table>